package chu.dejian.entity;

import android.os.Parcel;
import android.os.Parcelable;

import chu.dejian.widget.AttentionLevelView;

/**
 * Created by Administrator on 2015/12/12 0012.
 */
public class ContactEntity implements Parcelable{
    public int id;
    public String contactName;
    public String contactPhoneNum;
    public AttentionLevelView.ATTENTION_LEVEL attentionLevel;
    public int attentionStatus;

    public ContactEntity(){}

    public ContactEntity(String contactName, String contactPhoneNum) {
        this.contactName = contactName;
        this.contactPhoneNum = contactPhoneNum;
        this.attentionLevel = null;
    }

    public ContactEntity(String contactName, String contactPhoneNum, AttentionLevelView.ATTENTION_LEVEL attentionLevel) {
        this.contactName = contactName;
        this.contactPhoneNum = contactPhoneNum;
        this.attentionLevel = attentionLevel;
    }

    public ContactEntity(String contactName, String contactPhoneNum, int attentionLevelValue) {
        this.contactName = contactName;
        this.contactPhoneNum = contactPhoneNum;
        this.attentionLevel = AttentionLevelView.ATTENTION_LEVEL.fromInt(attentionLevelValue);
    }
    public ContactEntity(String contactName, String contactPhoneNum, int attentionLevelValue,int attentionStatus) {
        this.contactName = contactName;
        this.contactPhoneNum = contactPhoneNum;
        this.attentionLevel = AttentionLevelView.ATTENTION_LEVEL.fromInt(attentionLevelValue);
        this.attentionStatus = attentionStatus;
    }

    public ContactEntity(int id,String contactName, String contactPhoneNum, int attentionLevelValue) {
        this.id = id;
        this.contactName = contactName;
        this.contactPhoneNum = contactPhoneNum;
        this.attentionLevel = AttentionLevelView.ATTENTION_LEVEL.fromInt(attentionLevelValue);
    }

    protected ContactEntity(Parcel in) {
        id = in.readInt();
        contactName = in.readString();
        contactPhoneNum = in.readString();
        attentionStatus = in.readInt();
    }

    public static final Creator<ContactEntity> CREATOR = new Creator<ContactEntity>() {
        @Override
        public ContactEntity createFromParcel(Parcel in) {
            return new ContactEntity(in);
        }

        @Override
        public ContactEntity[] newArray(int size) {
            return new ContactEntity[size];
        }
    };

    @Override
    public boolean equals(Object o) {
        if(o == null) return false;
        if(this == o) return true;
        if(o instanceof ContactEntity){
            ContactEntity ce = (ContactEntity) o;
            return ce.id == id && ce.contactName.equals(contactName)
                    && ce.contactPhoneNum.equals(contactPhoneNum)
                    && ce.attentionLevel == attentionLevel;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return id + contactName.hashCode() + contactPhoneNum.hashCode()+ attentionLevel.ordinal();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(id);
        dest.writeString(contactName);
        dest.writeString(contactPhoneNum);
        dest.writeInt(attentionStatus);
    }
}
